﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Light.Framework.Contract;
using Light.Framework.Model;
using Light.Framework.Castle;
using NHibernate.Criterion;
using Light.Utility;

namespace Light.Framework.Component
{
    /// <summary>
    /// 日志组件
    /// </summary>
    public class LogComponent : BaseComponent<Log>, ILogComponent
    {

        #region ILogComponent 成员

        public IList<Log> Search(SearchArgs args, int pageIndex, int pageSize, out int totalResult, LogType type)
        {
            ICriterion criterion = Expression.Eq("LogType", type);
            if (args != null && args.ToCriterion<Log>() != null)
            {
                criterion = Expression.And(criterion, args.ToCriterion<Log>());
            }

            criterion = Expression.And(criterion, base.GetNotDeletedCriterion());
            return base.Search(criterion, pageIndex, pageSize, out totalResult);
        }

        public override OperateResult Delete(IList<Log> models)
        {
            OperateResult result = base.Delete(models);
            if (result.IsSucced)
            {
                ServerApplication.Logger.LogOperation("用户【" + ServerApplication.User.Name + "】清空【" + EnumHelper.GetEnumDesc(models[0].LogType) + "日志】");
            }
            return result;
        }

        #endregion


        public override Dictionary<string, string> SearchFields
        {
            get
            {
                base.SearchFields.Clear();
                base.SearchFields.Add("内容", "Content");
                return base.SearchFields;
            }
        }
    }
}
